package com.gxa.service.discrepancy.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.discrepancy.VisitRecord;
import com.gxa.entity.discrepancy.VisitorList;
import com.gxa.entity.discrepancy.search.VisitorRecordSearchMap;
import com.gxa.service.discrepancy.VisitRecordService;
import com.gxa.mapper.discrepancy.VisitRecordMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Set;

/**
* @author Administrator
* @description 针对表【visit_record(到访记录)】的数据库操作Service实现
* @createDate 2022-10-14 11:27:00
*/
@Service
public class VisitRecordServiceImpl extends ServiceImpl<VisitRecordMapper, VisitRecord>
    implements VisitRecordService{
    @Autowired
    private VisitRecordMapper mapper;
    @Override
    public PageInfo<VisitRecord> queryByPage(VisitorRecordSearchMap map) {
        PageHelper.startPage(map.getPageNum(),map.getPageSize());//1.开启分页

        QueryWrapper<VisitRecord> wrapper = new QueryWrapper<>();//2.条件构造器 模拟写动态sql  或者在xml 中写
        if (!StringUtils.isAnyBlank(map.getName())) {
            wrapper.like("visitor_name", map.getName());
        }

        if(!StringUtils.isAnyBlank(map.getPhone())){
            wrapper.like("phone",map.getPhone());
        }
        if(!StringUtils.isAnyBlank(map.getPassLocation())){
            wrapper.like("pass_loc",map.getPassLocation());
        }
        if(!StringUtils.isAnyBlank(map.getStartTime(),map.getEndTime())){
            wrapper.between("pass_time",map.getStartTime(),map.getEndTime());
        }
        PageInfo<VisitRecord> pageInfo = new PageInfo<>(mapper.selectList(wrapper));//3.获取分页信息
        return pageInfo;
    }

    @Override
    public Set<String> getLoc() {

        return mapper.getLoc();
    }
}




